package com.shuoyue.ycgk.utils;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import com.shuoyue.ycgk.Constant;
import com.shuoyue.ycgk.R;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

public class ShareUtil {
    public static String RUSH_URL = Constant.HOST_INTERFACE + "/api/share/sprint.html" + "?id=";//考前冲刺
    public static String PAPER_SET_URL = Constant.HOST_INTERFACE + "/api/share/questionBank.html" + "?id=";//真题、题库详情
    public static String BOOK_URL = Constant.HOST_INTERFACE + "/api/share/book.html" + "?id=";//书籍
    public static String MOK_URL = Constant.HOST_INTERFACE + "/api/share/mock.html" + "?id=";//模考详情
    public static String MOK_SORT_URL = Constant.HOST_INTERFACE + "/api/share/mockSort.html" + "?id=";//模考排行
    public static String GIFT_URL = Constant.HOST_INTERFACE + "/api/member/share?invUid=";//分享有礼
    public static String ESTIMATE_URL = Constant.HOST_INTERFACE + "/api/share/rank.html" + "?id=";//估分排行
    public static String RECURIMENT_URL = Constant.HOST_INTERFACE + "/api/share/notice.html" + "?id=";//公告详情
    public static String COURSE_URL = Constant.HOST_INTERFACE + "/api/share/course.html" + "?id=";//课程详情
    public static String NEWS_URL = Constant.HOST_INTERFACE + "/api/share/information.html" + "?id=";//资讯详情
    public static String JOB_URL = Constant.HOST_INTERFACE + "/api/share/post.html" + "?id=";//职位详情
    public static String QUESTION_URL = Constant.HOST_INTERFACE + "/api/share/assessment.html" + "?id=";//估分列表

    public static void shareUrl(Activity context, String url, String title, String brif, UMShareListener shareListener) {
        ShareAction mShareAction = new ShareAction(context)
                .setDisplayList(SHARE_MEDIA.WEIXIN
                        , SHARE_MEDIA.WEIXIN_CIRCLE
                        , SHARE_MEDIA.QQ
                        , SHARE_MEDIA.QZONE
//                        , SHARE_MEDIA.SINA
                )
                .addButton("复制链接", "复制链接", "umeng_socialize_copyurl", "umeng_socialize_copyurl")
                .setShareboardclickCallback((snsPlatform, share_media) -> {
                    if (snsPlatform.mShowWord.equals("复制文本")) {
                        getClip(context, title);
                        Toast.makeText(context, "已复制到剪贴板", Toast.LENGTH_LONG).show();
                    } else if (snsPlatform.mShowWord.equals("复制链接")) {
                        getClip(context, url);
                        Toast.makeText(context, "已复制到剪贴板", Toast.LENGTH_LONG).show();
                    } else {
                        UMWeb web = new UMWeb(url);
                        web.setTitle(title);
                        web.setThumb(new UMImage(context, R.drawable.share_icon));
                        web.setDescription(TextUtils.isEmpty(brif) ? "一锤公考 只讲干货 考上也全退" : brif);
                        new ShareAction(context).withMedia(web)
                                .setPlatform(share_media)
                                .setCallback(shareListener).share();
                    }
                });
        mShareAction.open();
    }


    public static void getClip(Context mContext, String text) {
        //获取剪贴板管理器
        ClipboardManager cm = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
// 创建普通字符型ClipData
        ClipData mClipData = ClipData.newPlainText("Label", text);
// 将ClipData内容放到系统剪贴板里。
        cm.setPrimaryClip(mClipData);
//        XToast.toast(mContext, "已复制到粘贴板");
    }
}
